home *** CD-ROM | disk | FTP | other *** search
- /***** BEGIN LICENSE BLOCK *****
- * Download Accelerator Plus Integration for Mozilla/Firefox.
- *
- * The contents of this file may be used under the terms of
- * Download Accelerator Plus (DAP) End User License Agreement, also
- * available at http://www.speedbit.com/Legal/DAPLICENSE.ASP ,
- * and is subject to the Speedbit Privacy Policy, also available
- * at http://www.speedbit.com/Legal/Privacy.ASP.
- *
- * Copyright (C) 1999-2006 SpeedBit Ltd.
- ***** END LICENSE BLOCK *****/
-
-
- /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- // Init : global object and listener to click
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- function Init()
- {
- DAP_Log("init");
- window.removeEventListener("load", Init, true);
-
-
- gDAPService = Components.classes["@speedbit/dapcomponent-service;1"]
- .getService(Components.interfaces.nsISupports).wrappedJSObject;
-
-
- if( !gDAPService )
- DAP_Log("problem create DAP service ");
-
-
- if( gDAPService.isMinIntegration() )
- {
- DAP_Log("Min integration Init ");
- return;
- }
-
- DAP_Log(window.navigator.userAgent);
-
-
-
- var appcontent = document.getElementById("appcontent"); // browser
- if(appcontent)
- {
- appcontent.addEventListener("load",myLoadPageExtention.onPageLoad, true);
- }
-
-
- var frames = document.getElementsByTagName ("iframe");
- for( var i = 0; i < frames .length ; i++)
- {
- DAP_Log("Frames");
- frames[i].addEventListener("load",myLoadPageExtention.onPageLoad, true);
-
- }
-
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
-
-
- ///////////////////////////////////////////////////////////////////////////////////////////////////////////
- function FindParentNode (node, parentNode)
- {
- DAP_Log("FindParentNode ");
- if (node && node.nodeType == Node.TEXT_NODE)
- {
- node = node.parentNode;
- }
- while (node)
- {
- var nodeName = node.localName;
- if (!nodeName)
- {
- return null;
- }
- nodeName = nodeName.toLowerCase();
- if (nodeName == "body" || nodeName == "html" || nodeName == "#document")
- {
- return null;
- }
- if (nodeName == parentNode)
- {
- return node;
- }
- node = node.parentNode;
- }
- return null;
- }
-
-
- /////////////////////////////////////////////////////////////////////////////////////////////////
- // Click monitor extention
- ///////////////////////////////////////////////////////////////////////////////////////////////////
- var myClickExtention =
- {
-
- ClickLink : function ( event )
- {
- DAP_Log("ClickLink");
-
- if( event.button == 0 && event.altKey )
- return;
-
- try
- {
- // function check if had been install DAP
- if( !gDAPService._runDAP() )
- {
- DAP_Log("Dap not exist from click handler");
- return;
- }
-
- var target = event.target;
-
- var linkNode = null;
- var localName = target.localName;
- if (localName) { localName = localName.toLowerCase(); }
- switch (localName)
- {
- case "a":
- case "area":
- case "link":
- if (target.hasAttribute("href"))
- {
- linkNode = target;
- }
- break;
- default:
- linkNode = FindParentNode(event.originalTarget, "a");
- if (linkNode && !linkNode.hasAttribute("href"))
- {
- linkNode = null;
- }
- break;
- }
-
-
- if (!linkNode)
- {
-
- DAP_Log("Link node NULL");
- return;
- }
-
-
- var href = linkNode.href;
- if (!href)
- {
- var wrapper = new XPCNativeWrapper(linkNode, "href", "getAttribute()");
- href = wrapper.href;
- }
-
- netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
- var obj = gDAPService.getDAPComponent();
- if( !obj )
- {
- DAP_Log("create instance null");
- return;
- }
-
- var doc = event.originalTarget.ownerDocument;
- // reffer
- var reffer = doc.location.href;
- // cookies
- var cook = doc.cookie;
- // description
- var description = getDescriptionFromDocument(linkNode.ownerDocument);
-
- DAP_Log(href);
- DAP_Log(reffer);
- DAP_Log(cook);
- DAP_Log(description);
- var userAgent = window.navigator.userAgent;
-
- if( event.button == 0 && event.altKey && event.ctrlKey)
- {
- DAP_Log(" press alt && click ");
- obj.SendToDAP(href,reffer,cook,description,userAgent);
- return;
-
- }
- // new click ,ask again
- gDAPService.setRegularDownload(false);
-
-
- if( !obj.IsShoudTrigger(href) )
- {
- DAP_Log("shoud trigger false");
- return;
- }
-
- if( !obj.IsAccelerate())
- {
- // continue download with FireFox
- gDAPService.setRegularDownload(true);
- return;
- }
-
-
- obj.SendToDAP(href,reffer,cook,description,userAgent);
- event.preventDefault();
- event.stopPropagation();
-
-
- }
- catch(ex)
- {
- DAP_Log(ex);
- }
-
- }
-
- };
- ////////////////////////////////////////////////////////////////////////////////////////////////////////
- var myLoadPageExtention =
- {
-
- onPageLoad: function(aEvent)
- {
-
- DAP_Log("onPageLoad");
- try
- {
- var doc = aEvent.originalTarget; // doc is document that triggered "onload" event
-
- if( !doc.links )
- return;
-
-
- for( var i = 0; i< doc.links.length ; i++ )
- doc.links[i].addEventListener("click",myClickExtention.ClickLink,true);
-
-
- }
- catch(e)
- {
- DAP_Log(e);
- }
- }
- };
-
-
- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
-
- // add overlay to load page
- window.addEventListener("load", Init, true);
-